package com.ssy.system.controller;

import com.ssy.common.utils.PageResult;
import com.ssy.common.utils.Result;
import com.ssy.system.pojo.Register;
import com.ssy.system.service.IRegisterService;
import com.ssy.system.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author ssy
 */
@RestController
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private IRegisterService registerService;

    /**
     * 挂号费的分页查询
     *
     * @param registerVo
     * @return
     */
    @GetMapping("/loadAllRegisterPage")
    public PageResult loadAllRegisterPage(RegisterVo registerVo) {
        return this.registerService.loadAllRegisterPage(registerVo);
    }

    /**
     * 添加挂号费
     *
     * @param register
     * @return
     */
    @PostMapping("/addRegister")
    public Result addRegister(@RequestBody Register register) {
        register.setCreateTime(new Date());
        return this.registerService.insertRegister(register);
    }

    /**
     * 修改挂号费
     *
     * @param register
     * @return
     */
    @PostMapping("/updateRegister")
    public Result updateRegister(@RequestBody Register register) {
        return this.registerService.updateRegister(register);
    }

    /**
     * 删除挂号费
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteRegister/{id}")
    public Result deleteRegister(@PathVariable Integer id) {
        return this.registerService.deleteRegisterById(id);
    }

    /**
     * 批量删除挂号费
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/bathDeleteRegister/{ids}")
    public Result bathDeleteRegister(@PathVariable Integer[] ids) {
        return this.registerService.bathDeleteRegister(ids);
    }

    /**
     * 修改挂号费状态
     *
     * @param id
     * @param state
     * @return
     */
    @PostMapping("/updateRegisterState/{id}/{state}")
    public Result updateRegisterState(@PathVariable Integer id, @PathVariable Integer state) {
        Register register = new Register();
        register.setId(id);
        register.setState(state);
        return this.registerService.updateRegister(register);
    }

    /**
     * 加载收费的下拉框
     *
     * @return data
     */
    @GetMapping("/loadAllRegisterByIDAndName")
    public Result loadAllRegisterByIDAndName() {
        return this.registerService.selectAllRegister();
    }

    /**
     * 根据ID查询一个
     *
     * @param id id
     * @return data
     */
    @GetMapping("/selectRegisterById/{id}")
    public Result selectRegisterById(@PathVariable Integer id) {
        Register register = this.registerService.getById(id);
        return new Result(register);
    }

}
